package com.atguigu.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @Description:
 * @Author: ruyi yang
 * @date 2021/8/5 17:41
 */
public class ListValueConstraintValidator implements ConstraintValidator<ListValue,Integer> {
    private final Set<Integer> set=new HashSet<>();

    @Override
    public boolean isValid(Integer v, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(v);
    }

    @Override
    public void initialize(ListValue constraintAnnotation) {
        int[] value = constraintAnnotation.vals();
        for (int i : value) {
            set.add(i);
        }
    }
}
